package com.share.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.share.domain.Angle;
import com.share.domain.Content;
import com.share.service.AngleService;
import com.share.mapper.AngleMapper;
import com.share.service.ContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 *
 */
@Service
public class AngleServiceImpl extends ServiceImpl<AngleMapper, Angle>
    implements AngleService{

    @Autowired
    ContentService contentService;


    public Page<Angle> findAngleByLexId(Integer lexId, Page page) {
        List<Content> contents = contentService.list(new QueryWrapper<Content>().eq("lex_id", lexId));
        if (contents.size()>=1){
            List<Integer> angleIds = contents.stream().map(c -> c.getAid()).collect(Collectors.toList());
            Page<Angle> anglePage = this.page(page, new QueryWrapper<Angle>().in("id", angleIds));
            return anglePage;
        }

        return new Page<Angle>().setRecords(new ArrayList<Angle>()).setCurrent(1).setTotal(0).setSize(5);
    }
}




